#pragma once

#include "vio/vio_common.h"

namespace vio {

// subpixel refinement of a reference feature patch with the current image.
// implements the inverse-compositional approach(see "Lucas-Kanade 20 Years
// on" paper by Baker.
namespace feature_alignment {

bool Align1D(const cv::Mat& cur_img,
             const Eigen::Vector2f&
                 dir,  // direction in which the the patch is allowed to move
             uint8_t* ref_patch_with_border,
             uint8_t* ref_patch,
             const int n_iter,
             Eigen::Vector2d& cur_px_estimate,
             double& h_inv);

bool Align2D(const cv::Mat& cur_img,
             uint8_t* ref_patch_with_border,
             uint8_t* ref_patch,
             const int n_iter,
             Eigen::Vector2d& cur_px_estimate,
             bool no_simd = false);

bool align2D_SSE2(const cv::Mat& cur_img,
                  uint8_t* ref_patch_with_border,
                  uint8_t* ref_patch,
                  const int n_iter,
                  Eigen::Vector2d& cur_px_estimate);

bool align2D_NEON(const cv::Mat& cur_img,
                  uint8_t* ref_patch_with_border,
                  uint8_t* ref_patch,
                  const int n_iter,
                  Eigen::Vector2d& cur_px_estimate);

}  // namespace feature_alignment
}  // namespace vio
